package com.kdl.webconfig.business;

import com.kdl.webconfig.entity.NewsDetail;
import com.kdl.webconfig.service.INewsDetailService;
import com.kdl.webconfig.vo.config.NewsDetailVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * @author 王成杰
 * @description TODO
 * @date 2022-09-14 下午8:12
 */
@Component
public class NewsDetailBusiness {


    @Autowired
    private INewsDetailService iNewsDetailService;

    public NewsDetailVO detail(Integer newsId){
        NewsDetailVO newsDetailVO = new NewsDetailVO();
        NewsDetail newsDetail = iNewsDetailService.selectOneByNewsId(newsId);
        if(Objects.nonNull(newsDetail)){
            newsDetailVO.setTitle(newsDetail.getTitle());
            newsDetailVO.setDate(newsDetail.getDate());
            newsDetailVO.setHtmlContent(newsDetail.getHtmlContent());
        }
        return newsDetailVO;
    }

    /**
     * 新闻明细更新
     * @param newsDetailVO
     * @return
     */
    public Boolean saveOrUpdate(NewsDetailVO newsDetailVO) {
        NewsDetail save = new NewsDetail();
        NewsDetail newsDetail = iNewsDetailService.selectOneByNewsId(newsDetailVO.getNewsId());
        if(Objects.nonNull(newsDetail)){
            save.setId(newsDetail.getId());
        }
        save.setNewsId(newsDetailVO.getNewsId());
        save.setDate(newsDetailVO.getDate());
        save.setTitle(newsDetailVO.getTitle());
        save.setHtmlContent(newsDetailVO.getHtmlContent());
        return iNewsDetailService.saveOrUpdate(save);
    }
}
